package com.yanqu.road.dao.impl.servercenter;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.minigame.MiniGameConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class MiniGameSortConfigDaoImpl extends TempDao {

    public Map<Integer, MiniGameConfig> getMiniGameConfigMap() {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, MiniGameConfig> dataMap = new HashMap<>();
        String sql = "select minGameId,sort,adId from t_s_mingame_start_template";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                MiniGameConfig data = new MiniGameConfig();
                data.setGameId(rs.getInt("minGameId"));
                data.setSort(rs.getInt("sort"));
                data.setAdId(rs.getInt("adId"));
                dataMap.put(data.getGameId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
